<template>
	<view class="container">
		<u-navbar title="切换房源" :autoBack="true" :fixed="true" :bgColor="'#ffffff'" :placeholder="true" :titleStyle="{
				color: '#333',
				fontSize: '16px',
			}"></u-navbar>

		<!-- 房源列表 -->
		<view class="house-list">
			<view :key="index" class="house-item" v-for="(item, index) in houseList"
				:class="{ active: selectedHouse === index }" @click="selectHouse(index)">
				<view class="house-info">
					<image class="house-img" :src="item.image" mode="aspectFill"></image>
					<view class="info-content">
						<view class="title">{{ item.title }}</view>
						<view class="room-info">
							<text class="label">房间号：</text>
							<text class="value">{{ item.roomNo }}</text>
						</view>
						<view class="owner-info">
							<text class="label">房东信息：</text>
							<text class="value">{{ item.ownerName }}；{{ item.ownerPhone }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部确认按钮 -->
		<view class="bottom-btn" @click="confirmSelect">确认</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				houseList: [{
						image: this.$Config.HTTP_REQUEST_URL + "/img/module_img1.png",
						title: "A101",
						roomNo: "07",
						ownerName: "刘",
						ownerPhone: "15297883",
					},
					{
						image: this.$Config.HTTP_REQUEST_URL + "/img/module_img1.png",
						title: "A101",
						roomNo: "07",
						ownerName: "刘",
						ownerPhone: "15297883",
					},
					{
						image: this.$Config.HTTP_REQUEST_URL + "/img/module_img1.png",
						title: "A101",
						roomNo: "07",
						ownerName: "刘",
						ownerPhone: "15297883",
					},
				],
				selectedHouse: null,
				selectedHouseInfo: null,
			};
		},
		methods: {
			selectHouse(index) {
				this.selectedHouse = index;
				this.selectedHouseInfo = this.houseList[index];
			},
			confirmSelect() {
				if (this.selectedHouseInfo) {
					console.log(111)
					// 返回上一页并传递选中的房源数据
					uni.$emit("houseSelected", this.selectedHouseInfo);
					uni.navigateBack();
				}
			},
		},
	};
</script>

<style lang="less" scoped>
	.container {
		min-height: 100vh;
		background-color: #f5f6fa;
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
	}

	.house-list {
		padding: 24rpx;

		.house-item {
			background: #fff;
			border-radius: 12rpx;
			padding: 24rpx;
			margin-bottom: 24rpx;
			transition: all 0.2s;

			&.active {
				background-color: #e2f0ff;
			}

			.house-info {
				display: flex;

				.house-img {
					width: 160rpx;
					height: 160rpx;
					border-radius: 8rpx;
					margin-right: 24rpx;
				}

				.info-content {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					flex: 1;

					.title {
						font-size: 26rpx;
						font-weight: 500;
						color: #222222;
					}

					.room-info,
					.owner-info {
						font-size: 26rpx;

						.label {
							color: #222;
						}

						.value {
							color: #999;
						}
					}
				}
			}
		}
	}

	.bottom-btn {
		position: fixed;
		left: 24rpx;
		right: 24rpx;
		bottom: calc(24rpx + env(safe-area-inset-bottom));
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: #2979ff;
		border-radius: 44rpx;
		color: #fff;
		font-size: 32rpx;
	}
</style>